import axios from 'axios'

export default {
  namespaced: true, // 命名空间
  state () {
    return {
      alllist: [1, 2, 3],
      // banner图
      banner: [],
      allCate: [],
      allLink: [],
      alltag: [],
      config: [],
      showBanner: [],
      sideBanner: [],
      hot: [],
      recommend: [],
      // 页面数据详情
      articledetail: []
    }
  },
  mutations: {
    list (state, data) {
      state.list = data
      // banner轮播
      state.banner = data.data.banner
      state.allCate = data.data.allCate
      state.allLink = data.data.allLink
      state.alltag = data.data.alltag
      state.showBanner = data.data.showBanner
      state.sideBanner = data.data.sideBanner
    },
    // 侧边内容
    list1 (state, data) {
      // 热门推荐
      state.hot = data.data.list
    },
    // 最新数据
    list2 (state, data) {
      state.recommend = data.data.list
    },
    // 查看详细数据
    list3 (state, data) {
      state.articledetail = data
      console.log(state.articledetail)
    }
  },

  actions: {
    async getAllArticle (store) {
      const { data: res } = await axios.get(
        'http://124.223.14.236:8060/home/index/index'
      )
      // 热门推荐
      const { data: hot } = await axios.get(
        'http://124.223.14.236:8060/home/index/hot'
      )

      // 最近更新
      const { data: recommend } = await axios.get(
        'http://124.223.14.236:8060/home/index/recommend'
      )

      // console.log(res)
      // console.log(hot)
      console.log(recommend)
      store.commit('list', res)
      store.commit('list1', hot)
      store.commit('list2', recommend)
    },
    async getdetails (store, id) {
      console.log('laoding...')

      // 获取数据详情
      const { data: res } = await axios({
        method: 'GET',
        url: 'http://124.223.14.236:8060/home/index/show',
        params: { id: id }
      })
      console.log(res)
      store.commit('list3', res.data.info)
    }
  },
  craeted () {
    this.getAllArticle()
  }
}
